﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Data.Car_Rental;
using Entity.Car_Rental;

namespace Car_Rental.Commons.Controllers.Helpers
{
    /// <summary>
    /// 前台后台都用到的controller
    /// </summary>
    public class AddressController : Controller
    {
        #region ajax获取收货地址

        public JsonResult AjaxGetAddress(string name, int length)
        {
            IAreaRepository _ICartService = new AreaRepository();
            JsonResult json = new JsonResult();
            List<Area> list = _ICartService.GetChildrenAddressByName(name, length);
            List<object> data = new List<object>();
            foreach (Area item in list)
            {
                data.Add(new { Text = item.Name, Value = item.Name });
            }
            json.Data = data;
            return json;
        }


        public JsonResult AjaxGetAddressByID(int codeID)
        {
            IAreaRepository _ICartService = new AreaRepository();
            JsonResult json = new JsonResult();
            List<Area> list = _ICartService.GetChildrenAddressByCodeID(codeID);
            List<object> data = new List<object>();
            foreach (Area item in list)
            {
                data.Add(new { Text = item.Name, Value = item.CodeID });
            }
            json.Data = data;
            return json;
        }
        #endregion

    }
}
